<?php

class Validate {

    static public function required(array $array,$required) {
        foreach ($required as $r) {
            if(empty($array[$r])) return FALSE;
        }
        return TRUE;
    }

    static public function getFailed(array $array, $required) {
        foreach ($required as $r) {
            if(empty($array[$r])) $failed[] = $r;
        }
        if(is_array($failed) && !empty($failed)) return $failed;
    }
    
    static public function verify(array $array,$args,$type='') {
        switch($type) {
            case 'GET':
                define("filterType",INPUT_GET);
             break;
             case 'POST':
             default:
                 define("filterType",INPUT_POST);
             break;
        }
        $array = self::sanitize($array);
        //check if variables exist, then run filter (sanitize,validate,options)
        if(is_array($args)) {
            foreach($args as $key => $arg) {
                if(!filter_has_var(filterType,$key)) throw new Exception('Missing '.$key.' in verification');
                if(is_array($arg)) $arg = implode(",",$arg);
                $array[$key] = filter_var($array[$key],$arg);
                //throw new Exception('Sanitizaztion failed on '.$key.', for filter : '.$arg.' on value : '.$array[$key]);
            }
        }
        return $array;
    }
    
    static public function sanitize($var) {
        if(!is_array($var)) return array($var);
        return $var;
    }
    
}

?>